{ Summer Informatics School.
  Problemset: http://agul-problems1.googlecode.com/svn/trunk/2010-2011/sis/problemset11.pdf
  Problem G
  Points: 17
}
uses SysUtils;                                
var n,m,r,i,j,h,t,k,g:longint; s:string; a:array[-10..1010,-10..1010] of byte; f:boolean; q:array[0..1000100,1..2] of longint;
procedure add(x,y:longint);
begin
inc(t);
q[t][1]:=x;
q[t][2]:=y;                             
a[x][y]:=1;                                              
end;
begin
fillchar(a,sizeof(a),0);
readln(s);                        
f:=false;
if s='INF' then f:=true else n:=strtoint(s);
readln(s);
if s='INF' then f:=true else m:=strtoint(s);
if not f then begin                                        
  r:=0;
  for k:=1 to n do begin
		for g:=1 to m do begin
      if a[k][g]=0 then begin
        inc(r);
        h:=1;
        t:=1;
				q[1][1]:=k;
        q[1][2]:=g;                              
        while h<=t do begin
          i:=q[h][1];
          j:=q[h][2];
          a[i][j]:=2;
          if (a[i-1][j-2]=0) and (i>1) and (j>2) then add(i-1,j-2);
          if (a[i-2][j-1]=0) and (i>2) and (j>1) then add(i-2,j-1);
          if (a[i-2][j+1]=0) and (i>2) and (j<m) then add(i-2,j+1);
          if (a[i-1][j+2]=0) and (i>1) and (j<m-1) then add(i-1,j+2);
          if (a[i+1][j-2]=0) and (i<n) and (j>2) then add(i+1,j-2);
          if (a[i+1][j+2]=0) and (i<n) and (j<m-1) then add(i+1,j+2);
          if (a[i+2][j-1]=0) and (i<n-1) and (j>1) then add(i+2,j-1);
          if (a[i+2][j+1]=0) and (i<n-1) and (j<m) then add(i+2,j+1);
          inc(h);
        end;
      end;
		end;
  end;
end;

if f then write('INF') else write(r);
end.
